Setting Filter issues

I used following code for setting filter

bool setFilter (Module m, string filtStr) {
    string code = "Module m = addr_ " ((addr_ m) int) "\ncurrent=m\nFilter f = " filtStr"\n; set f"
        noError(); eval_ code; return (null lastError) 
}

 


I tried to set filter on attributes which do not exists but although this function returns true.

Please reply how to avoid this.

Thanks & Regards,
Hardik Shah

 


SystemAdmin - Tue Mar 01 09:08:00 EST 2011

Re: Setting Filter issues
Mathias Mamsch - Tue Mar 01 10:57:09 EST 2011

The below seems to do the trick. Thanks for pointing this out. Regards, Mathias
 

bool setFilter (Module m, string filtStr) {
    string code = "
Module m = addr_ " ((addr_ m) int) "
current=m
Filter f = " filtStr"
string check = stringOf (m,f); if (null check) { return_ \"error\"; halt }
set f;return_ \"\""
        noError(); string msg = eval_ code; return (null lastError msg) 
}
 
string sErr = "attribute \"abcde\" == \"kljlkj\""
print "Error Case: " setFilter (current, sErr) "\n"
 
string sOk = "attribute \"Object Text\" == \"kljlkj\""
print "OK case: " setFilter (current, sOk) "\n"

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Setting Filter issues
SystemAdmin - Tue Mar 01 23:49:02 EST 2011

Mathias Mamsch - Tue Mar 01 10:57:09 EST 2011

The below seems to do the trick. Thanks for pointing this out. Regards, Mathias
 

bool setFilter (Module m, string filtStr) {
    string code = "
Module m = addr_ " ((addr_ m) int) "
current=m
Filter f = " filtStr"
string check = stringOf (m,f); if (null check) { return_ \"error\"; halt }
set f;return_ \"\""
        noError(); string msg = eval_ code; return (null lastError msg) 
}
 
string sErr = "attribute \"abcde\" == \"kljlkj\""
print "Error Case: " setFilter (current, sErr) "\n"
 
string sOk = "attribute \"Object Text\" == \"kljlkj\""
print "OK case: " setFilter (current, sOk) "\n"

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

thanks for the reply, I tried that but issue is if attribute does not exists then it throws error , instead of that is it possible to just tell the boolean status that whether filter is set or not so that execution is run smoothly.

Thanks,
Hardik Shah

Re: Setting Filter issues
Mathias Mamsch - Wed Mar 02 04:34:58 EST 2011

SystemAdmin - Tue Mar 01 23:49:02 EST 2011
thanks for the reply, I tried that but issue is if attribute does not exists then it throws error , instead of that is it possible to just tell the boolean status that whether filter is set or not so that execution is run smoothly.

Thanks,
Hardik Shah

If you are working on DOORS 9.2-1+ I guess you could be able to check for all the attributes, but on smaller DOORS versions I did not find a possibility to surpress the error. So you would need to parse the string in setFilter before actually applying it to a filter. Something like this:
 

Regexp greFilterAttribute = regexp "attribute \"([^\"]+)\""
 
bool setFilter (Module m, string filtStr) {
    bool allExist = true
        // parse the filter string
        Buffer b = create(); b = filtStr
        
        int pos = 0; 
        while (search(greFilterAttribute, b, pos)) {
                string aName = b[pos+start 1:pos+end 1]
                print "Checking Attribute:" aName     "\n"  
                int x = end 0
                pos += end 0
                AttrDef ad = find (m, aName)
                if (null ad || !ad.object) { allExist = false; break }
        }
 
        delete b
 
        if (!allExist) return false
 
        string code = "
Module m = addr_ " ((addr_ m) int) "
current=m
Filter f = " filtStr"
string check = stringOf (m,f); if (null check) { return_ \"error\"; halt }
set f;return_ \"\""
        noError(); string msg = eval_ code; return (null lastError msg) 
}
 
print "Error Filter:\n" 
{
string sErr = "attribute \"abcde\" == \"kljlkj\" && attribute \"Object Text\" == \"Hallo\""
print "Error Case: " setFilter (current, sErr) "\n"
}
 
print "Ok Filter:\n" 
{
 string sErr = "attribute \"Object Heading\" == \"kljlkj\" && attribute \"Object Text\" == \"Hallo\""
 print "OK Case: " setFilter (current, sErr) "\n"
}

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Setting Filter issues
SystemAdmin - Wed Mar 02 06:40:54 EST 2011

Mathias Mamsch - Wed Mar 02 04:34:58 EST 2011

If you are working on DOORS 9.2-1+ I guess you could be able to check for all the attributes, but on smaller DOORS versions I did not find a possibility to surpress the error. So you would need to parse the string in setFilter before actually applying it to a filter. Something like this:
 

Regexp greFilterAttribute = regexp "attribute \"([^\"]+)\""
 
bool setFilter (Module m, string filtStr) {
    bool allExist = true
        // parse the filter string
        Buffer b = create(); b = filtStr
        
        int pos = 0; 
        while (search(greFilterAttribute, b, pos)) {
                string aName = b[pos+start 1:pos+end 1]
                print "Checking Attribute:" aName     "\n"  
                int x = end 0
                pos += end 0
                AttrDef ad = find (m, aName)
                if (null ad || !ad.object) { allExist = false; break }
        }
 
        delete b
 
        if (!allExist) return false
 
        string code = "
Module m = addr_ " ((addr_ m) int) "
current=m
Filter f = " filtStr"
string check = stringOf (m,f); if (null check) { return_ \"error\"; halt }
set f;return_ \"\""
        noError(); string msg = eval_ code; return (null lastError msg) 
}
 
print "Error Filter:\n" 
{
string sErr = "attribute \"abcde\" == \"kljlkj\" && attribute \"Object Text\" == \"Hallo\""
print "Error Case: " setFilter (current, sErr) "\n"
}
 
print "Ok Filter:\n" 
{
 string sErr = "attribute \"Object Heading\" == \"kljlkj\" && attribute \"Object Text\" == \"Hallo\""
 print "OK Case: " setFilter (current, sErr) "\n"
}

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

thanks a lot...

It works as expected.

but just one minor favor, that is it will fail if the passed attribute value is not valid means if I had enumeration type and then I passed wrong value then it will not work as expected.

Thanks,
Hardik Shah

Re: Setting Filter issues
Mathias Mamsch - Wed Mar 02 10:10:38 EST 2011

SystemAdmin - Wed Mar 02 06:40:54 EST 2011
thanks a lot...

It works as expected.

but just one minor favor, that is it will fail if the passed attribute value is not valid means if I had enumeration type and then I passed wrong value then it will not work as expected.

Thanks,
Hardik Shah

If you want to do that, you need to parse the comparison values from the string too (extend the regexp by [^"]+"([^"]*)", to take into account all the operators like <, >, etc.). Extract the value from the second group, then check if the attribute has an enumeration type and check if the value is compatible with it (use the attributeValue function). Should be doable ... At the moment however I have no time for it.

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Setting Filter issues
SystemAdmin - Wed Mar 02 13:31:10 EST 2011

ok

Thanks & Regards,
Hardik Shah